package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Project_User;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class Project_UserDao {
	private DBHelp<Project_User> db = new DBHelp<Project_User>();
	public List<Project_User> findByUserId(int userid){
		String sql="SELECT projectid,userid FROM t_project_user WHERE userid =?";
		return db.executeQueryForList(sql, new Project_UserRowMapper(), userid);
	}
	public void insertPUByPU(Project_User pu){
		String sql="INSERT INTO t_project_user(projectid,userid) VALUES(?,?);";
		db.executeSQL(sql, pu.getProjectID(),pu.getUserID());
	}
	private class Project_UserRowMapper implements RowMapper<Project_User>{

		public Project_User mapperRow(ResultSet rs) throws SQLException {
			// TODO Auto-generated method stub
			Project_User pu = new Project_User();
			pu.setProjectID(rs.getInt("projectID"));
			pu.setUserID(rs.getInt("userID"));
			return pu;
		}
		
	}
}
